package com.example.juc.forkjoin;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.LongStream;

public class Test {


    // forkJoin
    public static void test() throws ExecutionException, InterruptedException {
        ForkJoinPool pool = new ForkJoinPool();
        ForkJoinTask<Long> task = new ForkJoinDemo(0,1000000000);
        ForkJoinTask<Long> submit = pool.submit(task);
        long sum = submit.get();
    }

    // stream 并行流
    public static void test3(){
        long sum = LongStream.rangeClosed(0,1000000000L).parallel().reduce(0,Long::sum);
    }

}


